package com.lancoo.answer.widget.combinationView;

import android.content.Context;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.lancoo.answer.R;
import com.lancoo.answer.model.bean.Child;
import com.lancoo.answer.model.bean.Item;
import com.lancoo.answer.util.ExamFontSizeAdjustUtils;
import com.lancoo.answer.util.RichTxtDealTuils;
import com.lancoo.answer.widget.audioPlayView.AudioPlayCallBack;


/**
 * Created by pengmi on 2021/12/7 11:45
 * Description:小题题干样式
 */
public class QueseBodyView extends RelativeLayout {

    private static final String TAG = "QueseBodyView";
    private TextView tv_queseBody;
    private boolean enableShowChildAsk=true;//是否显示题干信息
    private int showType=4;//4 普通横线
    private Child child;

    public QueseBodyView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public QueseBodyView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public QueseBodyView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context){
        LayoutInflater.from(context).inflate(R.layout.ev_layout_quese_body_view,this);
        tv_queseBody = findViewById(R.id.tv_quese_body);
        adjustFontSize();
    }

    public void initData(Child child){
        if(child==null){
            Log.e(TAG,"child is null");
            return;
        }
        this.child=child;
        ExamFontSizeAdjustUtils.adjustTextViewFontSize(tv_queseBody,15);
        if(showType==3){//填空题型查看作答
            RichTxtDealTuils.getFillLookingAnswerChildAsk(tv_queseBody,child,enableShowChildAsk);
        }else if(showType==2){//填空题查看原题样式呈现
            RichTxtDealTuils.getFillOrginalAnswerChildAsk(tv_queseBody, child, enableShowChildAsk);
        }else{//普通题干呈现
            RichTxtDealTuils.getNormalChildBody(tv_queseBody,child,enableShowChildAsk);
        }

        tv_queseBody.setMovementMethod(new LinkMovementMethod());

    }

    public void pause(){
        Log.e(TAG,"pause");
    }

    public void release(){
    }

    public void changeUIStyle(){
    }

    public void setEnableShowChildAsk(boolean enableShowChildAsk){
        this.enableShowChildAsk=enableShowChildAsk;
    }

    public void setShowType(int showType) {
        this.showType = showType;
    }

    public void setCallBack(AudioPlayCallBack callBack) {
    }


    public void adjustFontSize(){
        if(tv_queseBody==null||child==null){
            return;
        }
        ExamFontSizeAdjustUtils.adjustTextViewFontSize(tv_queseBody,15);
        if(showType==3){//填空题型查看作答
            RichTxtDealTuils.getFillLookingAnswerChildAsk(tv_queseBody,child,enableShowChildAsk);
        }else if(showType==2){//填空题查看原题样式呈现
            RichTxtDealTuils.getFillOrginalAnswerChildAsk(tv_queseBody, child, enableShowChildAsk);
        }else{//普通题干呈现
            RichTxtDealTuils.getNormalChildBody(tv_queseBody,child,enableShowChildAsk);
        }
    }

    public void markQuestion(){
        if(tv_queseBody==null||child==null){
            return;
        }
        Item item = child.getItemList().get(0);
        boolean itemMark = item.getItemMark();
        item.setItemMark(!itemMark);
        if(showType==3){//填空题型查看作答
            RichTxtDealTuils.getFillLookingAnswerChildAsk(tv_queseBody,child,enableShowChildAsk);
        }else if(showType==2){//填空题查看原题样式呈现
            RichTxtDealTuils.getFillOrginalAnswerChildAsk(tv_queseBody, child, enableShowChildAsk);
        }else{//普通题干呈现
            RichTxtDealTuils.getNormalChildBody(tv_queseBody,child,enableShowChildAsk);
        }
    }

}
